package com.mms.utils;

import com.mms.context.Constants;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * Created by dan3652@sina.com on 2016-12-29 14:00.
 */
public class UrlUtils {

    /**
     * URL 解码
     *
     * @return String
     * @author lifq
     * @date 2015-3-17 下午04:09:51
     */
    public static String getURLDecoderString(String str) {
        String result = "";
        if (null == str) {
            return "";
        }
        try {
            result = URLDecoder.decode(str, Constants.UTF8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
    /**
     * URL 转码
     *
     * @return String
     * @author lifq
     * @date 2015-3-17 下午04:10:28
     */
    public static String getURLEncoderString(String str) {
        String result = "";
        if (null == str) {
            return "";
        }
        try {
            result = java.net.URLEncoder.encode(str, Constants.UTF8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
       /* String str1 = "测试1";
        System.out.println(getURLEncoderString(str1));
        System.out.println(getURLDecoderString(getURLEncoderString(str1)));*/

        String str = "%u8463%u5B58%u745E%u70C8%u58EB%u7EAA%u5FF5%u9986";
        str = str.replace("%", "");
        System.out.println(str);
        //"\u8463\u5B58\u745E\u70C8\u58EB\u7EAA\u5FF5\u9986"
        System.out.println(UrlUtils.getURLDecoderString(str));
    }
}
